<template>
  <div class="app-container">
    <div class="chenjiaoheaderr">
      <div class="dsh" @click="getData(2)">待审核（{{nums.auditing}}）</div>
      <div class="ysz" @click="getData(4)">已收账（{{nums.pass}}）</div>
      <div class="bjj" @click="getData(3)">被拒绝（{{nums.refuse}}）</div>
    </div>
    <el-form :model="queryParams" ref="queryForm" :inline="true" label-width="100px">
      <el-form-item label="合同编号" prop="contractCode">
        <el-input
          v-model="queryParams.contractCode"
          placeholder="请输入合同编号"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="所属招商部" prop="ipdId">
        <el-select
          v-model="queryParams.ipdId"
          placeholder="请选择招商部"
          clearable
          size="small"
          style="width: 240px"
        >
          <el-option
            v-for="dept in deptList"
            :key="dept.deptId"
            :label="dept.deptName"
            :value="dept.deptId"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="成交经纪人" prop="dealAgent">
        <el-input
          v-model="queryParams.dealAgent"
          placeholder="请输入成交经纪人"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="提交时间" prop="submitTime">
        <!-- <el-date-picker clearable size="small" style="width: 200px"
          v-model="queryParams.submitTime"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="选择提交时间">
        </el-date-picker> -->
        <el-date-picker
          v-model="dateRange"
          size="small"
          style="width: 240px"
          value-format="yyyy-MM-dd"
          type="daterange"
          range-separator="至"
          start-placeholder="开始日期"
          end-placeholder="结束日期">
        </el-date-picker>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <!-- <el-col :span="1.5">
        <el-button
          type="primary"
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['dealrecord:dealrecord:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['dealrecord:dealrecord:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['dealrecord:dealrecord:remove']"
        >删除</el-button>
      </el-col> -->
      <el-col :span="1.5">
        <el-button
          type="warning"
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['dealrecord:dealrecord:export']"
        >导出</el-button>
      </el-col>
    </el-row>

    <el-table v-loading="loading" :data="dealrecordList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column type="index" align="center" />
      <el-table-column label="合同编号" align="center" prop="contractCode" />
      <el-table-column label="经纪人" align="center" prop="dealAgent" />
      <el-table-column label="承租方" align="center" prop="tenantry" />
      <el-table-column label="招商部" align="center" prop="organizationName" />
      <el-table-column label="月租金" align="center" prop="monthlyRent" />
      <el-table-column label="房号" align="center" prop="rooms" />
      <el-table-column label="招商提交结算时间" align="center" prop="submitTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.submitTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['dealrecord:dealrecord:edit']"
          >详情</el-button>
          <!-- <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['dealrecord:dealrecord:remove']"
          >删除</el-button> -->
        </template>
      </el-table-column>
    </el-table>
    
    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改成交记录管理对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="合同编号" prop="contractCode">
          <el-input v-model="form.contractCode" placeholder="请输入合同编号" />
        </el-form-item>
        <el-form-item label="所属招商部">
          <el-select v-model="form.ipdId" placeholder="请选择所属招商部">
            <el-option label="请选择字典生成" value="" />
          </el-select>
        </el-form-item>
        <el-form-item label="项目ID" prop="projectId">
          <el-input v-model="form.projectId" placeholder="请输入项目ID" />
        </el-form-item>
        <el-form-item label="楼宇ID" prop="buildingId">
          <el-input v-model="form.buildingId" placeholder="请输入楼宇ID" />
        </el-form-item>
        <el-form-item label="房源ID" prop="housingResourcesId">
          <el-input v-model="form.housingResourcesId" placeholder="请输入房源ID" />
        </el-form-item>
        <el-form-item label="月租金" prop="monthlyRent">
          <el-input v-model="form.monthlyRent" placeholder="请输入月租金" />
        </el-form-item>
        <el-form-item label="成交经纪人" prop="dealAgent">
          <el-input v-model="form.dealAgent" placeholder="请输入成交经纪人" />
        </el-form-item>
        <el-form-item label="经纪人联系方式" prop="telephone">
          <el-input v-model="form.telephone" placeholder="请输入经纪人联系方式" />
        </el-form-item>
        <el-form-item label="承租方" prop="tenantry">
          <el-input v-model="form.tenantry" placeholder="请输入承租方" />
        </el-form-item>
        <el-form-item label="承租方联系方式" prop="contactPhone">
          <el-input v-model="form.contactPhone" placeholder="请输入承租方联系方式" />
        </el-form-item>
        <el-form-item label="提交时间" prop="submitTime">
          <el-date-picker clearable size="small" style="width: 200px"
            v-model="form.submitTime"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="选择提交时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="附件" prop="enclosure">
          <el-input v-model="form.enclosure" placeholder="请输入附件" />
        </el-form-item>
        <el-form-item label="审核状态1审核中0拒绝2通过">
          <el-radio-group v-model="form.auditStatus">
            <el-radio label="1">请选择字典生成</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item label="未审核通过原因" prop="reason">
          <el-input v-model="form.reason" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="审核时间" prop="auditTime">
          <el-date-picker clearable size="small" style="width: 200px"
            v-model="form.auditTime"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="选择审核时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="最后修改时间" prop="modifiedTime">
          <el-date-picker clearable size="small" style="width: 200px"
            v-model="form.modifiedTime"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="选择最后修改时间">
          </el-date-picker>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listDealrecord, getDealrecord, deptList , delDealrecord, addDealrecord, updateDealrecord, exportDealrecord ,getAuditSituation} from "@/api/dealrecord/dealrecord";

export default {
  name: "Dealrecord",
  data() {
    return {
      nums:{},
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 总条数
      total: 0,
      // 成交记录管理表格数据
      dealrecordList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 部门列表
      deptList : [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        auditStatus:2,
        contractCode: undefined,
        ipdId: undefined,
        dealAgent: undefined,
      //  submitTime: undefined,
      },
      // 日期范围
      dateRange: [],
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      }
    };
  },
  created() {
    this.getData(2);
    this.getDeptList();
  },
  activated(){
    this.getData(this.queryParams.auditStatus);
  },
  methods: {
    //获取数据
    getData(e){
      this.queryParams.pageNum=1
      this.queryParams.pageSize= 10,
      this.queryParams.auditStatus=e
      getAuditSituation(this.id).then(response => {
       this.nums=response.data
      })
      this.getList();
    },
    // 获取部门数据
    getDeptList(){
      deptList().then(response =>{
        console.log(response.data)
        this.deptList = response.data
      })
    },
    /** 查询成交记录管理列表 */
    getList() {
      this.loading = true;
      listDealrecord(this.addDateRange(this.queryParams, this.dateRange)).then(response => {
        this.dealrecordList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.dateRange = [];
      this.form = {
        id: undefined,
        contractCode: undefined,
        ipdId: undefined,
        projectId: undefined,
        buildingId: undefined,
        housingResourcesId: undefined,
        monthlyRent: undefined,
        dealAgent: undefined,
        telephone: undefined,
        tenantry: undefined,
        contactPhone: undefined,
        submitTime: undefined,
        enclosure: undefined,
        auditStatus: "0",
        reason: undefined,
        auditTime: undefined,
        createTime: undefined,
        modifiedTime: undefined
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.dateRange = [];
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!=1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加成交记录管理";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      // this.reset();
      console.log(row)
      // encodeURIComponent(JSON.stringify(this.data.data))
      const id = row.id || this.ids
      this.$router.push({
        path:"/dealrecord/detail",
        query:{
          // data:encodeURIComponent(JSON.stringify(row))
          id
        }
      })
      // getDealrecord(id).then(response => {
      //   this.form = response.data;
      //   this.open = true;
      //   this.title = "修改成交记录管理";
      // });
    },
    /** 提交按钮 */
    submitForm: function() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != undefined) {
            updateDealrecord(this.form).then(response => {
              if (response.code === 200) {
                this.msgSuccess("修改成功");
                this.open = false;
                this.getList();
              }
            });
          } else {
            addDealrecord(this.form).then(response => {
              if (response.code === 200) {
                this.msgSuccess("新增成功");
                this.open = false;
                this.getList();
              }
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$confirm('是否确认删除成交记录管理编号为"' + ids + '"的数据项?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(function() {
          return delDealrecord(ids);
        }).then(() => {
          this.getList();
          this.msgSuccess("删除成功");
        }).catch(function() {});
    },
    /** 导出按钮操作 */
    handleExport() {
      const queryParams = this.queryParams;
      this.$confirm('是否确认导出所有成交记录管理数据项?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(function() {
          return exportDealrecord(queryParams);
        }).then(response => {
          this.download(response.msg);
        }).catch(function() {});
    }
  }
};
</script>
<style scoped>
  .chenjiaoheaderr{
    width: 100%;
    display: flex;
    justify-content: space-around;
  }
  .chenjiaoheaderr div{
    height: 150px;
    line-height: 150px;
    color: #000;
    font-size: 30px;
    font-weight: 500;
    cursor: pointer;
  }
</style>
